{include file='public/head'}
<body>
<div class="x-body">
    <form class="layui-form" id='mainForm' method="post" action="addUser">

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>用户角色</label>
            <div class="layui-input-block">
                <select lay-filter="group_id" name="group_id" id='group_id' lay-verify="required" lay-search>
                    <option value="">请选择角色</option>
                    {volist name='auth_group' id='vo'}
                    <option value="{$vo.id}" title="{$vo.type}" concierge="{$vo.concierge}" >{$vo.title}</option>
                    {/volist}
                </select>
                <input type="hidden" id="type" name="type" value="">
                <input type="hidden" id="concierge" name="concierge" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>用户名</label>
            <div class="layui-input-block">
                <input type="text" id="username" name="username" lay-verify="required|username" autocomplete="off"
                       placeholder="请输入用户名,只允许英文数字" class="layui-input" onkeyup="this.value=this.value.replace(/[^\w\.\/]/ig,'')">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>真实姓名</label>
            <div class="layui-input-block">
                <input type="text" id="truename" name="truename" lay-verify="required" autocomplete="off"
                       placeholder="请输入姓名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>邮&nbsp;&nbsp;&nbsp;箱</label>
            <div class="layui-input-block">
                <input type="text" id="email" name="email" placeholder="请输入注册邮箱" lay-verify="required"
                autocomplete="off" class="layui-input">
            </div>
        </div>

        {if $type == 1}
        <div class="layui-form-item">
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-block">
                <input type="text" id="company" name="company" placeholder="请输入公司名称，不输入则默认总公司"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">空间容量</label>
            <div class="layui-input-block">
                <input type="number" id="upload_capacity" name="upload_capacity" autocomplete="off"
                       placeholder="请输入允许上传文件空间大小" class="layui-input" min="0" value="50">
                <span style="position:absolute;top:10px;right:20px;">GB</span>
            </div>
        </div>
        {/if}

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>密&nbsp;&nbsp;&nbsp;码</label>
            <div class="layui-input-block">
                <input type="password" id="password" name="password" lay-verify="required|pass" placeholder="请输入密码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>确&nbsp;&nbsp;&nbsp;认</label>
            <div class="layui-input-block">
                <input type="password" id="check_password" name="check_password" lay-verify="required"
                       placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <div>
                <button style="width: 100%" class="layui-btn" lay-submit="" lay-filter="toSubmit">提交保存</button>
            </div>
        </div>
    </form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
    var form = layui.form;
    var layer = layui.layer;
    //监听提交
    form.on('submit(demo1)', function (data) {
        layer.alert(JSON.stringify(data.field), {
            title: '最终的提交信息'
        })
        return false;
    });

    form.on('select(group_id)', function (data) {
        $("#type").val(data.elem[data.elem.selectedIndex].title);
        $("#concierge").val(data.elem[data.elem.selectedIndex].getAttribute("concierge"));
    });
    $(document).ready(function () {
        var options = {
            type: 'post',           //post提交
            //url:'http://ask.tongzhuo100.com/server/****.php?='+Math.random(),   //url
            dataType: "json",        //json格式
            data: {},    //如果需要提交附加参数，视情况添加
            clearForm: false,        //成功提交后，清除所有表单元素的值
            resetForm: false,        //成功提交后，重置所有表单元素的值
            cache: false,
            async: false,          //同步返回
            success: function (data) {
                console.log(data);
                if (data.code == 0) {
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg, {icon: 1, time: 500}, function () {
                        $("#reset").click();
                        x_admin_close();
                        parent.location.reload();
                    });
                }
                //服务器端返回处理逻辑
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('操作失败:服务器处理失败');
            }
        };
        // bind form using 'ajaxForm'
        $('#mainForm').ajaxForm(options).submit(function (data) {
            //无逻辑
        });

    });

</script>
